﻿using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Employee = Core.Models.Employee;

namespace Test2010
{
    [TestClass]
    public class TestCasts
    {
        [TestMethod]
        public void Test1()
        {
            Console.WriteLine("4 = 3 + 1");
            Assert.AreEqual(4, 3 + 1);
        }

        [TestMethod]
        public void XmlSerializerTest()
        {
            var employee = new Employee
            {
                Email = "123@123.com",
                Name = "raymond",
                ID = 1,
                Phone = "12345678",
                Salary = 1000,
                No = "Abc123"
            };
            Console.WriteLine(employee.ToXmlString());
        }

        [TestMethod]
        public void NameofTest()
        {
            var employee = new Employee();
            Console.WriteLine(employee.Member(x => x.Phone));
            Console.WriteLine(Nameof<Employee>.Member(e => e.Salary));
        }
    }

    public static class Extensions
    {
        public static string ToXmlString(this object obj)
        {
            var sb = new StringBuilder();
            using (var writer = new StringWriter(sb))
            {
                var serializer = new XmlSerializer(obj.GetType());
                serializer.Serialize(writer, obj);
                return sb.ToString();
            }
        }
    }
}